package com.kkd.kkdapp.activity;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.kkd.kkdapp.base.BaseActivity;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.sina.weibo.sdk.api.share.BaseResponse;
import com.sina.weibo.sdk.api.share.IWeiboHandler;
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;

public class WeiboShareActivity extends BaseActivity implements
		IWeiboHandler.Response {

	public IWeiboShareAPI mWeiboShareAPI;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = this.getIntent();
		final String inviteFriendUrl = intent.getStringExtra("inviteFriendUrl");
		final String title = intent.getStringExtra("title");
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		final String content = intent.getStringExtra("content")+"——"+time.format(nowTime)+"——";
		int logoInt = intent.getIntExtra("logoInt", -1);
		String logoStr = intent.getStringExtra("logoStr");
		if (logoInt != -1) {
			Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),
					logoInt);
			sendMessage(this, inviteFriendUrl, title, content, bitmap);
		}
		if (!TextUtils.isEmpty(logoStr)) {
			ImageLoader.getInstance().loadImage(logoStr,
					new ImageLoadingListener() {

						@Override
						public void onLoadingStarted(String imageUri, View view) {
							// TODO Auto-generated method stub

						}

						@Override
						public void onLoadingFailed(String imageUri, View view,
								FailReason failReason) {
							// TODO Auto-generated method stub

						}

						@Override
						public void onLoadingComplete(String imageUri,
								View view, Bitmap loadedImage) {
							// TODO Auto-generated method stub
							sendMessage(WeiboShareActivity.this,
									inviteFriendUrl, title, content,
									loadedImage);
						}

						@Override
						public void onLoadingCancelled(String imageUri,
								View view) {
							// TODO Auto-generated method stub

						}
					});
		}
	}

	@Override
	public void onResponse(BaseResponse baseResp) {
		super.onResponse(baseResp);
		finish();
	}
}
